var app = getApp();
var util = require("../../utils/libs.js")
var api = require("../../utils/api.js")
var data = require("../../utils/date.js")
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
     skillList:[],
     uid:"",
     page:1,
     limit:99999
  },
  onLoad (options) {
    let that = this
    let uid = wx.getStorageSync('uid')
    that.setData({
      uid:uid
    })
    // 页面初始化 options为页面跳转所带来的参数
    that.startList()
  },
  startList(){
    let that = this
    util.request(api.starList,{
    uid:that.data.uid,
    page:that.data.page,
    limit:that.data.limit
    },"GET")
    .then(function (res) {
      if(res.error_code === 0){
        console.log(res)
        var arr = [];
        for(var i=0;i<res.data.list.length;i++){
          console.log(res.data.list[i].article);
          if(res.data.list[i].article != null){
              arr.push(res.data.list[i])
          }
        }
        arr.forEach(val => {
            val.article.create_time = data.data(val.article.create_time)
            var content = val.article.content
            console.log(content)
            WxParse.wxParse('content', 'html', content, that, 0);
            // 获取文章内容
            var s = '';
            var s2 = that.getContent(s);
            val.article.content = s2.substring(0,30)

        });
        that.setData({
          skillList:arr
        })
        console.log(that.data.skillList)
      }
    })
  },
  getContent(s) {
    //获取文章内容节点
    var nodes = wx.getStorageSync('htmldata');
    var arr = nodes.nodes;
    console.log(arr);
    for (var i = 0; i < arr.length; i++) {
      var arr2 = arr[i].nodes;
      //console.log(arr2);
      for (var j = 0; j < arr2.length; j++) {
        var arr3 = arr2[j].nodes
        if (arr3 != undefined) {
          for (var l = 0; l < arr3.length; l++) {
            var arr4 = arr3[l].nodes;
            if (arr4 != undefined) {
              for (var m = 0; m < arr4.length; m++) {
                s += arr4[m].text;
              }
            }
          }
        }
      }
    }
    return s
  },
  godetail(event){
   let id = event.currentTarget.dataset.id
    wx.navigateTo({
      url:"/pages/article/article?id="+id
    })
  }
})
